﻿using System;
using System.Diagnostics.Contracts;

namespace RobotRules.Cache
{
    /// <summary>
    /// Robot cache API
    /// </summary>
    [ContractClass(typeof(CacheContract))]
    public interface ICache : IDisposable
    {
        /// <summary>
        /// Add a new document to the cache
        /// </summary>
        /// <param name="url">Robot file uri</param>
        /// <param name="content">File content</param>
        /// <exception cref="ArgumentNullException"><paramref name="url"/> is null</exception>
        /// <exception cref="ArgumentException"><paramref name="content"/> is null or empty</exception>
        void Add(Uri url, string[] content);
        /// <summary>
        /// Delete a robot file
        /// </summary>
        /// <param name="url">Robot file uri</param>
        /// <exception cref="ArgumentNullException"><paramref name="url"/> is null</exception>
        void Delete(Uri url);
        /// <summary>
        /// Get the date when the file has been cached
        /// </summary>
        /// <param name="url">Robot file uri</param>
        /// <exception cref="ArgumentNullException"><paramref name="url"/> is null</exception>
        /// <returns>Date</returns>
        [Pure]
        DateTime? GetDate(Uri url);
        /// <summary>
        /// Update a robot file
        /// </summary>
        /// <param name="url">Robot file uri</param>
        /// <param name="content">File content</param>
        /// <exception cref="ArgumentNullException"><paramref name="url"/> is null</exception>
        /// <exception cref="ArgumentException"><paramref name="content"/> is null or empty</exception>
        void Update(Uri url, string[] content);
        /// <summary>
        /// Check if a file exists
        /// </summary>
        /// <param name="url">Robot file uri</param>
        /// <exception cref="ArgumentNullException"><paramref name="url"/> is null</exception>
        /// <returns><c>True</c> if the file exists, <c>False</c> instead</returns>
        [Pure]
        bool Exists(Uri url);
        /// <summary>
        /// Get robot file content
        /// </summary>
        /// <param name="url">Robot file uri</param>
        /// <exception cref="ArgumentNullException"><paramref name="url"/> is null</exception>
        /// <returns>File content</returns>
        [Pure]
        string[] GetFile(Uri url);
        /// <summary>
        /// Clear the cache
        /// </summary>
        void Clear();
    }
}
